package models;

import java.io.Serializable;
import javax.persistence.*;

import prefix.util.JPAUtil;
import prefix.util.jpaQueryfier.JpaQueryfier;

import repository.OrderRepository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The persistent class for the order database table.
 * 
 */
@Entity
@Table(name = "OORDER")
public class Order implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @TableGenerator(
            name = "ORDER_SEQ",
            table = "SEQUENCE",
            pkColumnName = "NAME",
            pkColumnValue = "ORDER_SEQ",
            valueColumnName = "CNT",
            initialValue = 10000,
            allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "ORDER_SEQ")
    @Column(unique = true, nullable = false)
    private Integer id;

    private Integer aid;

    private double amount;

    @Column(name = "CART_ID")
    private Integer cartId;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "CREATE_D")
    private Date createD;

    private int status;

    private int type;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "UPDATE_D")
    private Date updateD;

    @Transient
    private List<OrderDetail> detailList = null;

    public Order() {
    }

    public Order(int aid, double amount, int cartId) {
        this.aid = aid;
        this.amount = amount;
        this.cartId = cartId;
        this.status = Status.NEW.ordinal();
        this.type = Type.USER_GEN.ordinal();
        this.createD = new Date();
    }

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getAid() {
        return this.aid;
    }

    public void setAid(Integer aid) {
        this.aid = aid;
    }

    public double getAmount() {
        return this.amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public Integer getCartId() {
        return this.cartId;
    }

    public void setCartId(Integer cartId) {
        this.cartId = cartId;
    }

    public Date getCreateD() {
        return this.createD;
    }

    public void setCreateD(Date createD) {
        this.createD = createD;
    }

    public Status getStatus() {
        return Status.values()[this.status];
    }

    public void setStatus(Status status) {
        this.status = status.ordinal();
    }

    public Type getType() {
        return Type.values()[this.type];
    }

    public void setType(Type type) {
        this.type = type.ordinal();
    }

    public Date getUpdateD() {
        return this.updateD;
    }

    public void setUpdateD(Date updateD) {
        this.updateD = updateD;
    }

    public List<OrderDetail> getDetailList() {
        if (this.detailList == null)
            this.detailList = OrderRepository.getListByProperty(OrderDetail.class, "orderId", this.getId());
        return detailList;
    }

    public void setDetailList(List<OrderDetail> detailList) {
        this.detailList = detailList;
    }

    public enum Type {
        USER_GEN, // 0 - user generated/customized
        SYSTEM_GEN, // 1 - system recommended
    }

    public static enum Status {
        NEW("New"), // 0 -
        COMMITTED("Committed"); // 1 -

        private String _label;

        private Status(String label) {
            _label = label;
        }

        public String getLabel() {
            return _label;
        }

    }

    public static enum ColumnsGetSummaryDataSQL {
        total_received_int,
        total_invest,
        total_received_prncp,
        total_accrue_amount,
        out_prncp,
        total_accrue_int
    }



   

}